import { IMOptionsType } from "@/types/dict";
import { handleSearchLoading, handleSearchTime } from "@userList/search";
import {
  columns,
  defaultColumns,
  defaultSearchList,
  searchList,
  tabPower,
  tableActiveKey,
} from "./store";
import { refreshTable } from ".";
const searchLoading = ref(false);
const resetLoading = ref(false);
export const searchConfig = () => {
  const defineSearch = {
    okText: getProxyT("base.query"),
    cancelText: getProxyT("base.reset"),
    searchLoading,
    resetLoading,
    refreshTableData: async (searchParams: any, type: any) => {
      handleSearchTime(["start_date", "end_date"], searchParams);
      handleSearchLoading(true, type, defineSearch);
      if (tableActiveKey.value === 1) {
        handleSearchTime(
          ["op_start_date", "op_end_date"],
          searchParams,
          undefined,
          "operateStart_operateEnd"
        );
      }
      await refreshTable(searchParams);
      handleSearchLoading(false, type, defineSearch);
    },
    tabsSlot: {
      activeKey: tableActiveKey,
      on: {
        change(tableActiveKey: any) {
          initObjAttr(columns, defaultColumns[tableActiveKey]);
          searchList.value = defaultSearchList[tableActiveKey];
          refreshTable();
        },
      },
      options: ([] as IMOptionsType[])
        .concat(
          tabPower[0]
            ? {
                label: getProxyT("auth0"),
                value: 0,
              }
            : []
        )
        .concat(
          tabPower[1]
            ? {
                label: getProxyT("popular11"),
                value: 1,
              }
            : []
        ),
    },
    searchList,
  };
  return defineSearch;
};
